def ttt(y):    
    if y == 1: return False    
    o = True    
    k = y - 1    
    while k > 1:    
        if not y % k:    
            o = False                
            break    
        k -= 1        
    return o  
      
g = input()  
r = []  
for i in range(len(g)):  
    for k in range(i + 1,len(g) + 1):  
        y = int(g[i:k]) 
        if ttt(y):  
            r += [y]  
print(max(r) if r else 0)
